package com.binarycat.dynamiclimit.bean;

import java.util.List;

import com.binarycat.dynamiclimit.collector.AbstractLimitDataCollector;
import com.binarycat.dynamiclimit.interceptor.HandlerAfterLimit;
import com.binarycat.dynamiclimit.limiter.policy.AbstractLimitPolicy;

/**
 * 动态限流的相关参数配置
 * 
 * @author jjb
 * @date 2018/08/06
 */
public class DynamicLimiterConfig {
    /**
     * qps保护值,即:无论如何限流,qps最低限制到qps保护值
     */
    private int qpsProtectionValue = 30;

    /**
     * cpu负载限流阀值
     */
    private double cpuLimitRateThreshold = 0.80;

    /**
     * 内存使用率限流阀值
     */
    private double memoryLimitRateThreshold = 0.80;

    /**
     * 超时时间限流阀值(单位:毫秒)
     */
    private double timeOutLimitRateThreshold = 2000;

    /**
     * 异常率限流阀值
     */
    private double exceptionLimitRateThreshold = 0.2;

    /**
     * 开启限流后,qps升高或降低的比例
     */
    private double qpsChangeRate = 0.05;

    /**
     * 限流策略扩展集合
     */
    private List<AbstractLimitPolicy> limitPolicyExtendList;

    /**
     * 限流收集器扩展
     */
    private AbstractLimitDataCollector limitDataCollectorExtend;

    /**
     * 特定的异常集合(只有发生特定异常时,才会用于用于异常率的统计)
     */
    private List<Class<? extends Throwable>> specificExceptions;
    
    /**
     *限流后的请求处理逻辑(如:某url限流后,默认返回特定的字符串或特定的页面)
     */
    private HandlerAfterLimit handlerAfterLimit;

    /**
     * 是否需要打印限流日志
     */
    private boolean needPrintLimitRateLog = false;

    /**
     * 构造方法
     */
    public DynamicLimiterConfig() {

    }

    public int getQpsProtectionValue() {
        return qpsProtectionValue;
    }

    public void setQpsProtectionValue(int qpsProtectionValue) {
        this.qpsProtectionValue = qpsProtectionValue;
    }

    public double getCpuLimitRateThreshold() {
        return cpuLimitRateThreshold;
    }

    public void setCpuLimitRateThreshold(double cpuLimitRateThreshold) {
        this.cpuLimitRateThreshold = cpuLimitRateThreshold;
    }

    public double getMemoryLimitRateThreshold() {
        return memoryLimitRateThreshold;
    }

    public void setMemoryLimitRateThreshold(double memoryLimitRateThreshold) {
        this.memoryLimitRateThreshold = memoryLimitRateThreshold;
    }

    public double getTimeOutLimitRateThreshold() {
        return timeOutLimitRateThreshold;
    }

    public void setTimeOutLimitRateThreshold(double timeOutLimitRateThreshold) {
        this.timeOutLimitRateThreshold = timeOutLimitRateThreshold;
    }

    public double getExceptionLimitRateThreshold() {
        return exceptionLimitRateThreshold;
    }

    public void setExceptionLimitRateThreshold(double exceptionLimitRateThreshold) {
        this.exceptionLimitRateThreshold = exceptionLimitRateThreshold;
    }

    public double getQpsChangeRate() {
        return qpsChangeRate;
    }

    public void setQpsChangeRate(double qpsChangeRate) {
        this.qpsChangeRate = qpsChangeRate;
    }

    public List<AbstractLimitPolicy> getLimitPolicyExtendList() {
        return limitPolicyExtendList;
    }

    public void setLimitPolicyExtendList(List<AbstractLimitPolicy> limitPolicyExtendList) {
        this.limitPolicyExtendList = limitPolicyExtendList;
    }

    public AbstractLimitDataCollector getLimitDataCollectorExtend() {
        return limitDataCollectorExtend;
    }

    public void setLimitDataCollectorExtend(AbstractLimitDataCollector limitDataCollectorExtend) {
        this.limitDataCollectorExtend = limitDataCollectorExtend;
    }

    public List<Class<? extends Throwable>> getSpecificExceptions() {
        return specificExceptions;
    }

    public void setSpecificExceptions(List<Class<? extends Throwable>> specificExceptions) {
        this.specificExceptions = specificExceptions;
    }

    public boolean isNeedPrintLimitRateLog() {
        return needPrintLimitRateLog;
    }

    public void setNeedPrintLimitRateLog(boolean needPrintLimitRateLog) {
        this.needPrintLimitRateLog = needPrintLimitRateLog;
    }

    public HandlerAfterLimit getHandlerAfterLimit() {
        return handlerAfterLimit;
    }

    public void setHandlerAfterLimit(HandlerAfterLimit handlerAfterLimit) {
        this.handlerAfterLimit = handlerAfterLimit;
    }

}
